package com.eyeem.recyclerviewtools.sample.xrecyclerview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;

import java.util.ArrayList;
import java.util.List;

public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter {
    protected String TAG = this.getClass().getSimpleName();
    protected Context mContext;
    protected List<T> mInfos = new ArrayList<>();
    protected LayoutInflater mInflater;
    protected int screenWidth = 0;
    protected OnItemClickListener mItemListener;

    public BaseRecyclerAdapter(Context context, List<T> infos) {
        this.mContext = context;
        this.mInfos = infos;
        this.mInflater = LayoutInflater.from(context);
        this.screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mItemListener = listener;
    }

    @Override
    public int getItemCount() {
        return mInfos != null ? mInfos.size() : 0;
    }

    public T getItem(int position) {
        return mInfos != null ? mInfos.get(position) : null;
    }

    public void clear() {
        this.mInfos.clear();
        notifyDataSetChanged();
    }

    public List<T> getLists() {
        return mInfos;
    }

    public void setLists(List<T> infos) {
        this.mInfos = infos;
    }

}
